<?php

namespace App\Service\AppStore;

use App\Helpers\AliyunUtil;
use App\Model\UserProfile;
use App\Model\UserRecValue;
use App\Service\BaseService;

/**
 * 匹配-星球用户列表
 */
class MatchUserListService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        // $where = [
        //     ['avatar', '<>', '']
        // ];
        // $data = UserProfile::where($where)->orderBy('user_id', 'desc')->limit(40)->get()->toArray();
        $userIds = UserProfile::getRecUsers(0);
        if (!$userIds) $userIds = UserRecValue::getNewUsers();
        $userIds = array_slice($userIds, 0, 40);
        $data = UserProfile::getUsersProfile($userIds, false, true);
        $ret = ['list' => []];
        array_walk($data, function ($user) use (&$ret) {
            $ret['list'][] = [
                'user_id' => $user['user_id'],
                'nick_name' => $user['nick_name'],
                'avatar' => AliyunUtil::IMG_HOST . $user['avatar'],
            ];
        });
        return $ret;
    }
}
